package com.bw.shop2208a.car

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bw.shop2208a.entity.*
import com.bw.shop2208a.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CarViewModel : BaseViewModel() {
    val successCar = MutableLiveData<GetCarEntity>()
    val failCar = MutableLiveData<String>()

    fun getCar(){
        viewModelScope.launch {
            try {
                successCar.value = apiservice.getCar()
            } catch (e: Exception) {
                failCar.value = e.message
            }
        }
    }

    var successAddCar = MutableLiveData<AddCarResult>()
    var failAddCar = MutableLiveData<String>()

    fun addCar(addcarParam: AddcarParam){
        viewModelScope.launch {
            try {
                successAddCar.value = apiservice.addCar(addcarParam)
            } catch (e: Exception) {
                failAddCar.value = e.message
            }
        }
    }

    var successDeleteCar = MutableLiveData<DeleteResult>()
    var failDeleteCar = MutableLiveData<String>()

    fun deleteCar(deleteCarParam: DeleteCarParam){
        viewModelScope.launch {
            try {
                successDeleteCar.value = apiservice.deleteCar(deleteCarParam)
            } catch (e: Exception) {
                failDeleteCar.value = e.message
            }
        }
    }
}